package com.example.baseapp.common;


import com.example.baseapp.common.enums.ResponseCode;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * Result class
 *
 * @author zhangl
 * @date 2022/3/23 11:42
 */
@Slf4j
@Data
public class Result<T> {
    private Integer status;
    private String message;
    private T data;
    private long timestamp;

    public Result() {
        this.timestamp = System.currentTimeMillis();
    }
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setStatus(ResponseCode.SUCCESS.getCode());
        result.setMessage(ResponseCode.SUCCESS.getMessage());
        return result;
    }
    public static <T> Result<T> success(Integer code, String message){
        Result<T> result = new Result<T>();
        result.setStatus(code);
        result.setMessage(message);
        return result;
    }
    public static <T> Result<T> fail(Integer code, String message) {
        Result<T> result = new Result<T>();
        result.setStatus(code);
        result.setMessage(message);
        return result;
    }
}
